// pages/jielong/member_list/member_list.js
const util = require("../../../util/util.js");
var app = getApp();//引用app.js
var commonURL = app.data.baseURL;
var commonURLYY = app.data.newURL;
var commonURLXX = app.data.lastURL;
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  goarea: function () {
    wx.navigateTo({
      url: '../selectarea/selectarea',
    })
  },
  getName: function (e) {
    console.log(e)
    this.setData({
      name: e.detail.value
    })
  },
  phoneNum: function (e) {
    console.log(e)
    this.setData({
      phonenum: e.detail.value
    })
  },
  weichat: function (e) {
    console.log(e)
    this.setData({
      wechatnum: e.detail.value
    })
  },
  explain: function (e) {
    console.log(e)
    this.setData({
      notice: e.detail.value
    })
  },
  fans: function (e) {
    console.log(e)
    this.setData({
      fans: e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    wx.getStorage({
      key: 'xiaoqu',
      success: function (res) {
        that.setData({
          areaid: res.data.id,
          address: res.data.item.address
        })
      },
      fail: function (res) {

      }
    })
  },
  formSubmit: function (e) {
    var list = [];
    let formObj = {
      phonenum: this.data.phonenum,
      name: this.data.name,
      areaid: this.data.areaid,
      notice: this.data.notice,
      wechatnum: this.data.wechatnum
    };
    if (formObj.name == '' || !formObj.name) {
      wx.showToast({
        title: '姓名不能为空！',
        icon: 'none',
        duration: 4000
      })
      return false;
    }
    if (!(/^1[34578]\d{9}$/.test(formObj.phonenum))) {
      wx.showToast({
        title: '手机号输入有误！',
        icon: 'none',
        duration: 4000
      })
      return false;
    }
    if (formObj.areaid == '' || !formObj.areaid) {
      wx.showToast({
        title: '请选择小区！',
        icon: 'none',
        duration: 4000
      })
      return false;
    }
    if (formObj.wechatnum == '' || !formObj.wechatnum) {
      wx.showToast({
        title: '请填写微信号',
        icon: 'none',
        duration: 4000
      })
      return false;
    }
    list.push(formObj)
    wx.request({
      url: commonURL + 'op=team_member',
      data: {
        list: list,
        openid: wx.getStorageSync('openid'),
        unionId: app.data.unionId || wx.getStorageSync('unionId'),
        uniacid: app.data.GZHid
      },
      success: function (res) {
        console.log(res)
        if (res.data.status == 1) {
          wx.showModal({
            title: '提示',
            content: res.data.data.message,
            showCancel: false,
            complete: function () {
              wx.redirectTo({
                url: '../Tindex/Tindex',
              })
            }
          })
        } else {
          wx.showToast({
            title: res.data.data.message,
            icon: 'none',
            duration: 4000
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
})